﻿<common:LayoutAwarePage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ShopPowerTemplate"
    xmlns:common="using:ShopPowerTemplate.Common"
    xmlns:controls="using:ShopPowerTemplate.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:data="using:ShopPowerTemplate.Data"
    xmlns:rate="using:Callisto.Controls"
    x:Name="pageRoot"
    x:Class="ShopPowerTemplate.ProductViewPage"
    xmlns:Controls="using:Callisto.Controls"
    mc:Ignorable="d">

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition x:Name="headerRow" Height="140"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyleCustom}" />
            <StackPanel x:Name="headerStackPanel" Grid.Column="1" Orientation="Horizontal">
                <Border x:Name="headerBorder" Height="80" Padding="0,0,20,0" Margin="0,0,20,0" BorderBrush="{StaticResource ApplicationHeaderForegroundThemeBrush}">
                    <Image x:Name="headerImage" Source="ms-appx:///Assets/LogoShop.png" Stretch="Uniform" />
                </Border>
            </StackPanel>
            <controls:ShoppingCartButton x:Name="shoppingCartButton" Grid.Column="1" Margin="0,0,50,0" HorizontalAlignment="Right" VerticalAlignment="Center"/>
        </Grid>

        <ScrollViewer x:Name="scrollViewer" Grid.ColumnSpan="2" Grid.Row="1" Padding="120,0,40,0" Style="{StaticResource HorizontalScrollViewerStyle}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                    <RowDefinition Height="Auto"></RowDefinition>
                </Grid.RowDefinitions>

                <TextBlock x:Name="titleSnapped"
                    Style="{StaticResource SnappedTitleTextStyle}" 
                    Foreground="{StaticResource ApplicationForegroundThemeBrush}"
                    Text="{Binding Product.Name}" 
                    Margin="0,0,0,10" 
                    Visibility="Collapsed"/>

                <FlipView 
                    x:Name="imagesFlipView"
                    MaxWidth="450" 
                    HorizontalAlignment="Left" 
                    VerticalAlignment="Stretch" 
                    ItemsSource="{Binding ImagePresenterList}"
                    Margin="0,0,0,80">
                    <FlipView.ItemTemplate>
                        <DataTemplate>
                            <Image Source="{Binding BitmapImage}" Stretch="Uniform" />
                        </DataTemplate>
                    </FlipView.ItemTemplate>
                </FlipView>

                <Grid x:Name="productDetailPanel" Margin="50,0,0,0" Grid.Column="1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"></RowDefinition>
                        <RowDefinition Height="*"></RowDefinition>
                    </Grid.RowDefinitions>
                    <StackPanel x:Name="productHeaderGrid">
                        <TextBlock Style="{StaticResource HeaderTextStyle}" 
                                   Text="{Binding Product.Name}" 
                                   Margin="0,0,0,10"
                                   x:Name="title"/>
                        <StackPanel x:Name="ratingPanel" Orientation="Horizontal">
                            <Controls:Rating x:Name="StarRating" 
                                             IsHitTestVisible="False"
                                             ItemCount="5" 
                                             Value="{Binding Product.AverageReview, Converter={StaticResource RatingMultiplierConverter}}" 
                                             HorizontalAlignment="Center" 
                                             VerticalAlignment="Bottom"
                                             Margin="-2,0,10,0"
                                             Foreground="{StaticResource ApplicationHeaderForegroundThemeBrush}"/>
                            <TextBlock TextWrapping="Wrap"
                                       Style="{StaticResource SubheaderTextStyle}"
                                       Foreground="{StaticResource ApplicationHeaderForegroundThemeBrush}"
                                       Text="Escribir una opinión" 
                                       Tapped="AddReview_Tapped"
                                       HorizontalAlignment="Center" 
                                       VerticalAlignment="Stretch"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" Margin="3,30,0,10">
                            <TextBlock x:Name="infoTab" Text="Información" Style="{StaticResource SubheaderTextStyle}" 
                                       Tapped="Informacion_Tapped"  
                                       Margin="0,0,40,0" />
                            <TextBlock Text="{Binding Reviews.Count, Converter={StaticResource StringFormatConverter}, ConverterParameter=Opiniones&#x00a0;(\{0\})}" 
                                       Style="{StaticResource SubheaderTextStyle}" 
                                       Tapped="Opiniones_Tapped" />
                        </StackPanel>
                    </StackPanel>

                    <Grid x:Name="informationGrid" Grid.Row="1" Margin="0,0,0,100">
                        <Grid Margin="0,0,0,100">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"></RowDefinition>
                                <RowDefinition Height="Auto"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Border
                                Background="{StaticResource ApplicationHeaderForegroundThemeBrush}"
                                HorizontalAlignment="Stretch" 
                                VerticalAlignment="Stretch"
                                Padding="20,10"
                                Width="698"
                                Margin="4">
                                <TextBlock 
                                    Style="{StaticResource SubheaderTextStyle}"
                                    Foreground="{StaticResource ApplicationPageBackgroundThemeBrush}"
                                    Text="{Binding Product.Description}" 
                                    TextWrapping="Wrap"/>
                            </Border>
                            <Grid Grid.Row="1" x:Name="OptionTypesGrid">
                                <ListView 
                                    x:Name="optionsListView"
                                    HorizontalAlignment="Right" 
                                    Margin="0,10"
                                    Padding="0"
                                    ItemsSource="{Binding ProductOptions}"
                                    ItemTemplate="{StaticResource Standard80OptionTypesTemplateCustom}"
                                    SelectionMode="None"
                                    IsSwipeEnabled="false"
                                    IsItemClickEnabled="True" 
                                    ItemContainerStyle="{StaticResource OptionItemContainerStyle}"
                                    />
                            </Grid>
                        </Grid>
                        <StackPanel x:Name="addToCartPanel" 
                            Orientation="Horizontal" 
                            HorizontalAlignment="Right" 
                            VerticalAlignment="Bottom">
                            <TextBlock 
                                VerticalAlignment="Center"
                                HorizontalAlignment="Center"
                                Style="{StaticResource HeaderTextStyle}"
                                Text="{Binding Product.Price, Converter={StaticResource StringFormatConverter}, ConverterParameter=\{0:c\}}" 
                                />
                            <Button 
                                x:Name="addToCartButton"
                                Command="{Binding AddProductCommand}"
            		            CommandParameter="{Binding}"
            		            Content="Añadir al carrito" 
                                Margin="30,5,0,5" 
                                Height="60" 
                                Width="230"
                                HorizontalAlignment="Center"
                                FontSize="26.667"
                                FontWeight="Normal"/>
                        </StackPanel>
                    </Grid>

                    <ListView x:Name="ratingGrid" 
                        HorizontalAlignment="Left" 
                        VerticalAlignment="Top" 
                        Visibility="Collapsed"
                        Grid.Row="1"
                        Margin="0"
                        Padding="0"
                        ItemsSource="{Binding Reviews}"
                        ItemTemplate="{StaticResource ReviewItemTemplate}"
                        SelectionMode="None"
                        IsSwipeEnabled="false"
                        IsItemClickEnabled="True" 
                        ItemContainerStyle="{StaticResource OptionItemContainerStyle}"
                        />
                </Grid>
            </Grid>
        </ScrollViewer>

        <Border x:Name="bottomShoppingCartButton" Height="60" Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{StaticResource ApplicationHeaderForegroundThemeBrush}" Visibility="Collapsed">
            <controls:ShoppingCartButton x:Name="shoppingCartButton1" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{StaticResource ApplicationPageBackgroundThemeBrush}"/>
        </Border>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait" />
                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedButtonStyleCustom}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="scrollViewer" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource VerticalScrollViewerStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="scrollViewer" Storyboard.TargetProperty="Padding">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="20"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="productDetailPanel" Storyboard.TargetProperty="(Grid.Column)">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="productDetailPanel" Storyboard.TargetProperty="(Grid.ColumnSpan)">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="productDetailPanel" Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Orientation" Storyboard.TargetName="ratingPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Vertical"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Orientation" Storyboard.TargetName="addToCartPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Vertical"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="HorizontalAlignment" Storyboard.TargetName="addToCartPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="addToCartButton">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0,5"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="title">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="titleSnapped">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="shoppingCartButton">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="bottomShoppingCartButton">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.Column)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.ColumnSpan)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(StackPanel.Orientation)" Storyboard.TargetName="headerStackPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Vertical"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Border.BorderThickness)" Storyboard.TargetName="headerBorder">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.HorizontalAlignment)" Storyboard.TargetName="headerBorder">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Center"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="headerBorder">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="headerImage">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="40,20,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.Row)" Storyboard.TargetName="imagesFlipView">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="1"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Width" Storyboard.TargetName="imagesFlipView">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="270"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Height" Storyboard.TargetName="imagesFlipView">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="270"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="imagesFlipView">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="infoTab">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0,0,25,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.Row)" Storyboard.TargetName="productDetailPanel">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="2"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ItemTemplate" Storyboard.TargetName="optionsListView">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedOptionTypesTemplate}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="informationGrid">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Height" Storyboard.TargetName="headerRow">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="100"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible" Storyboard.TargetName="ratingGrid">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="False"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="ItemTemplate" Storyboard.TargetName="ratingGrid">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedReviewItemTemplate}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

    </Grid>
</common:LayoutAwarePage>
